﻿using System.Web.Mvc;
using System.Web.Routing;
using Smarly.Web.Controllers;
using Smarly.Web.RouteConstraints;

namespace Smarly.Web.App_Start
{
	public class RouteConfig
	{
		public static void RegisterRoutes(RouteCollection routes)
		{
			routes.RouteExistingFiles = true;

			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
			routes.IgnoreRoute("robots.txt");
			routes.IgnoreRoute("favicon.ico");
			routes.IgnoreRoute("{file}.txt");
			routes.IgnoreRoute("{file}.htm");
			routes.IgnoreRoute("{file}.html");
			routes.IgnoreRoute("{file}.xml");
			routes.IgnoreRoute("{file}.js");
			routes.IgnoreRoute("{file}.css");
			routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" });
			routes.IgnoreRoute("api/{*pathInfo}");
			routes.IgnoreRoute("jslibs/{*pathInfo}");
			routes.IgnoreRoute("img/{*pathInfo}");
			routes.IgnoreRoute("css/{*pathInfo}");
			routes.IgnoreRoute("Scripts/{*pathInfo}");

			routes.IgnoreRoute("apple-touch-icon.png");
			routes.IgnoreRoute("apple-touch-icon-precomposed.png");
			routes.IgnoreRoute("admin/{*pathInfo}");



			#region Notification

			routes.MapRoute(
					"Notification_MessageError",
					"notification/messageerror",
					new { controller = "Notification", action = "MessageError" },
					new { },
					new[] { typeof(Smarly.Web.Controllers.NotificationController).Namespace }
			);

			#endregion

			#region Yandex.Money

			routes.MapRoute(
					"Yandex_ClientToken",
					"payment/yandex/buy/{purchaseId}/{purchaseHashCode}",
					new { controller = "Yandex", action = "Payment" },
					new { },
					new[] { typeof(Smarly.Web.Controllers.YandexController).Namespace }
			);

			routes.MapRoute(
					"Yandex",
					"payment/yandex/{bookId}/{value}",
					new { controller = "Yandex", action = "Index" },
					new { },
					new[] { typeof(Smarly.Web.Controllers.YandexController).Namespace }
			);

			routes.MapRoute(
					"Yandex_post",
					"payment/yandex",
					new { controller = "Yandex", action = "Index"},
					new { },
					new[] { typeof(Smarly.Web.Controllers.YandexController).Namespace }
			);

			#endregion

			#region Social Post

			routes.MapRoute(
					"SocialPost",
					"socialpost",
					new { controller = "socialpost", action = "Index" },
					new { },
					new[] { typeof(Smarly.Web.Controllers.SocialPostController).Namespace }
			);

			#endregion

			#region Subscriber

			routes.MapRoute(
					"Subscriber_Subscribe",
					"subscribe",
					new { controller = "Subscriber", action = "Index" },
					new { },
					new[] { typeof(Smarly.Web.Controllers.SubscriberController).Namespace }
			);

			routes.MapRoute(
					"Subscriber_Unsubscribe",
					"subscribe/unsubscribe/{Email}/{ActivationCode}",
					new { controller = "Subscriber", action = "Unsubscribe" },
					new { },
					new[] { typeof(Smarly.Web.Controllers.SubscriberController).Namespace }
			);

			#endregion

			#region Account

			routes.MapRoute(
				"SignInAccountDialog",
				"dialog/account",
				new {controller = "Account", action = "Index"},
				new {},
				new[] {typeof (AccountController).Namespace}
				);

			routes.MapRoute(
				"CreateAccountDialog",
				"dialog/account/create",
				new {controller = "Account", action = "Create"},
				new {},
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"RepearAccountDialog",
				"dialog/account/repear",
				new {controller = "Account", action = "Repear"},
				new {},
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"UpdateAccountDialog",
				"dialog/account/update/{hashcode}",
				new { controller = "Account", action = "UpdatePassword", hashcode = UrlParameter.Optional },
				new {},
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"SignOutAccount",
				"account/logout",
				new { controller = "Account", action = "Logout" },
				new {},
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"Account_UserInfo",
				"account/{emailsh1}",
				new { controller = "Account", action = "UserInfo" },
				new {},
				new[] { typeof(AccountController).Namespace }
				);

			#endregion


			#region Home

			routes.MapRoute(
				"About",
				"about",
				new {controller = "Home", action = "About"},
				new {},
				new[] {typeof (HomeController).Namespace}
				);


			routes.MapRoute(
				"Home",
				"",
				new {controller = "Home", action = "Index"},
				new {},
				new[] {typeof (HomeController).Namespace}
				);

			routes.MapRoute(
				"Chapter",
				"{*parts}",
				new {controller = "Home", action = "Text"},
				new {},
				new[] {typeof (HomeController).Namespace}
				);

			#endregion		
		}
	}
}